package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceName;
import com.ruoyi.service.service.IServiceNameService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 耗材别名Controller
 * 
 * @author ZDL
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/service/name")
public class ServiceNameController extends BaseController
{
    @Autowired
    private IServiceNameService serviceNameService;

    /**
     * 查询耗材别名列表
     */
    @PreAuthorize("@ss.hasPermi('service:name:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceName serviceName)
    {
        startPage();
        List<ServiceName> list = serviceNameService.selectServiceNameList(serviceName);
        return getDataTable(list);
    }

    /**
     * 导出耗材别名列表
     */
    @PreAuthorize("@ss.hasPermi('service:name:export')")
    @Log(title = "耗材别名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceName serviceName)
    {
        List<ServiceName> list = serviceNameService.selectServiceNameList(serviceName);
        ExcelUtil<ServiceName> util = new ExcelUtil<ServiceName>(ServiceName.class);
        util.exportExcel(response, list, "耗材别名数据");
    }

    /**
     * 获取耗材别名详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:name:query')")
    @GetMapping(value = "/{nameId}")
    public AjaxResult getInfo(@PathVariable("nameId") Long nameId)
    {
        return success(serviceNameService.selectServiceNameByNameId(nameId));
    }

    /**
     * 新增耗材别名
     */
    @PreAuthorize("@ss.hasPermi('service:name:add')")
    @Log(title = "耗材别名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceName serviceName)
    {
        return toAjax(serviceNameService.insertServiceName(serviceName));
    }

    /**
     * 修改耗材别名
     */
    @PreAuthorize("@ss.hasPermi('service:name:edit')")
    @Log(title = "耗材别名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceName serviceName)
    {
        return toAjax(serviceNameService.updateServiceName(serviceName));
    }

    /**
     * 删除耗材别名
     */
    @PreAuthorize("@ss.hasPermi('service:name:remove')")
    @Log(title = "耗材别名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{nameIds}")
    public AjaxResult remove(@PathVariable Long[] nameIds)
    {
        return toAjax(serviceNameService.deleteServiceNameByNameIds(nameIds));
    }
}
